<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta name="generator" content="PHPDoctor 2RC4 (http://peej.github.com/phpdoctor/)">
<meta name="when" content="Mon, 02 May 2011 02:46:56 +0000">

<link rel="stylesheet" type="text/css" href="../stylesheet.css">
<link rel="start" href="../overview-summary.html">

<title>system.php (Cornice)</title>

</head>
<body id="file" onload="parent.document.title=document.title;">

<div class="header">
<h1>Cornice</h1>
<ul>
<li><a href="../overview-summary.html">Overview</a></li>
<li>Package</li><li>Class</li><li>Tree</li><li><a href="../overview-files.html">Files</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../todo-list.html">Todo</a></li>
<li><a href="../index-all.html">Index</a></li>
</ul>
</div>

<div class="small_links">
<a href="../index.html" target="_top">Frames</a>
<a href="../source\system.php.html" target="_top">No frames</a>
</div>
<hr>

<h1>system.php</h1>
<div class="comment" id="overview_description"><p>============================================================================
Cornice PHP Framework & Website Builder
Freeware (f) 2011 by Inforo Software & Computer
============================================================================</p></div>

<hr>

<a name="line1"></a><pre><?php
<a name="line2"></a>/**
<a name="line3"></a> *============================================================================
<a name="line4"></a> * Cornice PHP Framework & Website Builder
<a name="line5"></a> * Freeware (f) 2011 by Inforo Software & Computer
<a name="line6"></a> *============================================================================
<a name="line7"></a> */
<a name="line8"></a> 
<a name="line9"></a>/**
<a name="line10"></a> * Main class of Cornice core
<a name="line11"></a> * @author Nicola Dinh
<a name="line12"></a> * @version 2011.04.2216
<a name="line13"></a> */
<a name="line14"></a>class system {
<a name="line15"></a>
<a name="line16"></a>  /*
<a name="line17"></a>   * All properties
<a name="line18"></a>   */
<a name="line19"></a>  public static $devmode = false; 
<a name="line20"></a>  private static $module = null; //multi-level array (info only)
<a name="line21"></a>  private static $page = null; //multi-level array (info only)
<a name="line22"></a>
<a name="line23"></a>  public static $skin = null; //current skin
<a name="line24"></a>  public static $lang = null; //current language
<a name="line25"></a> 
<a name="line26"></a>  private static $layout_obj = null;
<a name="line27"></a>  private static $page_obj = null;  
<a name="line28"></a>  public static $blocks = array(); //list of loaded blocks
<a name="line29"></a>  
<a name="line30"></a>  public static $title = null;
<a name="line31"></a>  public static $website = null;
<a name="line32"></a>
<a name="line33"></a>  /**
<a name="line34"></a>   * Default instance level constructor
<a name="line35"></a>   * Just decorative, should not be called due to having only static methods
<a name="line36"></a>   */
<a name="line37"></a>  public function __construct() {
<a name="line38"></a>    //
<a name="line39"></a>  }
<a name="line40"></a>  
<a name="line41"></a>  /**
<a name="line42"></a>   * Get requested module information (from module xml)
<a name="line43"></a>   * @return array The array parsed from module xml
<a name="line44"></a>   */
<a name="line45"></a>  public static function get_module_info() {
<a name="line46"></a>    return self::$module;
<a name="line47"></a>  }
<a name="line48"></a>
<a name="line49"></a>  /**
<a name="line50"></a>   * Get requested page information (from page xml)
<a name="line51"></a>   * @return array The array parsed from page xml
<a name="line52"></a>   */
<a name="line53"></a>  public static function get_page_info() {
<a name="line54"></a>    return self::$page;
<a name="line55"></a>  }
<a name="line56"></a>  
<a name="line57"></a>  /**
<a name="line58"></a>   * Load all PHP classes in a certain directory
<a name="line59"></a>   * @param string $dir_path The path to directory
<a name="line60"></a>   * @return boolean 'true' if all files loaded well, 'false' otherwise
<a name="line61"></a>   */
<a name="line62"></a>  private static function load_php_classes($dir_path) {
<a name="line63"></a>    if (file_exists("$dir_path/classes.txt")) {
<a name="line64"></a>      $classes = file("$dir_path/classes.txt");
<a name="line65"></a>      foreach ($classes as $class) {
<a name="line66"></a>        $class = trim($class);
<a name="line67"></a>        require_once("$dir_path/$class.php");
<a name="line68"></a>      }
<a name="line69"></a>      return;
<a name="line70"></a>    }
<a name="line71"></a>    
<a name="line72"></a>    //if 'classes.txt' not found
<a name="line73"></a>    $dir_handle = opendir($dir_path);
<a name="line74"></a>    if ($dir_handle===false)
<a name="line75"></a>      return false;
<a name="line76"></a>    
<a name="line77"></a>    //load files
<a name="line78"></a>    while (($file=readdir($dir_handle))!==false)
<a name="line79"></a>      if (is_file("$dir_path/$file"))
<a name="line80"></a>        require_once("$dir_path/$file");      
<a name="line81"></a>      
<a name="line82"></a>    //close dir  
<a name="line83"></a>    closedir($dir_handle);
<a name="line84"></a>    return true;
<a name="line85"></a>  }
<a name="line86"></a>  
<a name="line87"></a>  /**
<a name="line88"></a>   * Load all core classes
<a name="line89"></a>   */
<a name="line90"></a>  public static function load_core_classes() {
<a name="line91"></a>    self::load_php_classes("classes/core/bases");
<a name="line92"></a>    self::load_php_classes("classes/core/statics");
<a name="line93"></a>    self::load_php_classes("classes/core/dynamics");
<a name="line94"></a>  }
<a name="line95"></a>  
<a name="line96"></a>  /**
<a name="line97"></a>   * Load all custom classes
<a name="line98"></a>   */
<a name="line99"></a>  public static function load_custom_classes() {
<a name="line100"></a>    self::load_php_classes("classes/customs/bases");
<a name="line101"></a>    self::load_php_classes("classes/customs/statics");
<a name="line102"></a>    self::load_php_classes("classes/customs/dynamics");  
<a name="line103"></a>  }
<a name="line104"></a>
<a name="line105"></a>  /**
<a name="line106"></a>   * Load module information (from 'modules/module.xml')
<a name="line107"></a>   */
<a name="line108"></a>  public static function load_module_info() {
<a name="line109"></a>    $module = request::get_module_name();
<a name="line110"></a>    $module_xml = "modules/$module.xml";
<a name="line111"></a>    
<a name="line112"></a>    //check file
<a name="line113"></a>    if (!file_exists($module_xml)) {
<a name="line114"></a>      response::error("'$module_xml' not found");
<a name="line115"></a>      exit;
<a name="line116"></a>    }
<a name="line117"></a>    
<a name="line118"></a>    //load xml
<a name="line119"></a>    self::$module = xml::arr_from_file($module_xml); 
<a name="line120"></a>  }
<a name="line121"></a>  
<a name="line122"></a>  /**
<a name="line123"></a>   * Load page information (from 'mcv/pages/views/xml/page.xml')
<a name="line124"></a>   */
<a name="line125"></a>  public static function load_page_info() {
<a name="line126"></a>    $module = request::get_module_name();
<a name="line127"></a>    $page = request::get_page_name(); 
<a name="line128"></a>    $page_xml = "mcv/pages/views/xml/$module"."_"."$page"."_page".".xml";
<a name="line129"></a>    
<a name="line130"></a>    //check page xml file
<a name="line131"></a>    if (!file_exists($page_xml)) {
<a name="line132"></a>      response::error("'$page_xml' not found");
<a name="line133"></a>      exit;
<a name="line134"></a>    }
<a name="line135"></a>    
<a name="line136"></a>    //load page xml
<a name="line137"></a>    self::$page = xml::arr_from_file($page_xml); 
<a name="line138"></a>  }
<a name="line139"></a>
<a name="line140"></a>  /**
<a name="line141"></a>   * Create layout object
<a name="line142"></a>   */
<a name="line143"></a>  private static function create_layout_obj() {
<a name="line144"></a>    $layout = utils::get_arr_value(self::$page,"layout");
<a name="line145"></a>
<a name="line146"></a>    //file paths    
<a name="line147"></a>    $mdl_path = "mcv/layouts/models/shared_".$layout."_layout_model.php";
<a name="line148"></a>    $cls_path = "mcv/layouts/controllers/shared_".$layout."_layout.php";
<a name="line149"></a>    $css_path = "mcv/layouts/views/css/shared_".$layout."_layout.css";
<a name="line150"></a>    $js_path = "mcv/layouts/views/js/shared_".$layout."_layout.js";
<a name="line151"></a>    $php_path = "mcv/layouts/views/php/shared_".$layout."_layout.php";
<a name="line152"></a>    
<a name="line153"></a>    //load classes
<a name="line154"></a>    if (!file_exists($mdl_path)) {
<a name="line155"></a>      response::error("'$mdl_path' not found");
<a name="line156"></a>      exit;
<a name="line157"></a>    }
<a name="line158"></a>    if (!file_exists($cls_path)) {
<a name="line159"></a>      response::error("'$cls_path' not found");
<a name="line160"></a>      exit;
<a name="line161"></a>    }
<a name="line162"></a>    require_once($mdl_path); //model
<a name="line163"></a>    require_once($cls_path); //controller
<a name="line164"></a>
<a name="line165"></a>    //create instance of layout
<a name="line166"></a>    $layout_class = "shared_".$layout."_layout";
<a name="line167"></a>    $model_class = $layout_class."_model";
<a name="line168"></a>    $layout_obj = new $layout_class();
<a name="line169"></a>    $model_obj = new $model_class();
<a name="line170"></a>    
<a name="line171"></a>    //set properties
<a name="line172"></a>    $model_obj->class_path = $mdl_path;
<a name="line173"></a>    $layout_obj->class_path = $cls_path;    
<a name="line174"></a>    $layout_obj->css_path = $css_path;
<a name="line175"></a>    $layout_obj->js_path = $js_path;
<a name="line176"></a>    $layout_obj->php_path = $php_path;
<a name="line177"></a>    $layout_obj->model = $model_obj;
<a name="line178"></a>
<a name="line179"></a>    self::$layout_obj = $layout_obj;    
<a name="line180"></a>  }
<a name="line181"></a>  
<a name="line182"></a>  /**
<a name="line183"></a>   * Create page object
<a name="line184"></a>   */
<a name="line185"></a>  private static function create_page_obj() {
<a name="line186"></a>    $module = request::get_module_name();
<a name="line187"></a>    $page = request::get_page_name();
<a name="line188"></a>    $skin = self::$skin; 
<a name="line189"></a>
<a name="line190"></a>    //file paths    
<a name="line191"></a>    $mdl_path = "mcv/pages/models/$module"."_".$page."_page_model.php";
<a name="line192"></a>    $cls_path = "mcv/pages/controllers/$module"."_".$page."_page.php";
<a name="line193"></a>    $css_path = "mcv/pages/views/css/$module"."_".$page."_".$skin.".css";
<a name="line194"></a>    $js_path = "mcv/pages/views/js/$module"."_".$page."_page.js";
<a name="line195"></a>    $php_path = "mcv/pages/views/php/$module"."_".$page."_page.php";
<a name="line196"></a>    
<a name="line197"></a>    //block has css to follow skin, but if so such css file, use default
<a name="line198"></a>    //skin file of block (ie. $module_$block_block.css)
<a name="line199"></a>    if (!file_exists($css_path))    
<a name="line200"></a>      $css_path = "mcv/pages/views/css/$module"."_".$page."_page.css";
<a name="line201"></a>    
<a name="line202"></a>    //load classes
<a name="line203"></a>    if (!file_exists($mdl_path)) {
<a name="line204"></a>      response::error("'$mdl_path' not found");
<a name="line205"></a>      exit;
<a name="line206"></a>    }
<a name="line207"></a>    if (!file_exists($cls_path)) {
<a name="line208"></a>      response::error("'$cls_path' not found");
<a name="line209"></a>      exit;
<a name="line210"></a>    }    
<a name="line211"></a>    require_once($mdl_path); //model
<a name="line212"></a>    require_once($cls_path); //controller
<a name="line213"></a>
<a name="line214"></a>    //create instance of layout
<a name="line215"></a>    $page_class = $module."_".$page."_page";
<a name="line216"></a>    $model_class = $page_class."_model";
<a name="line217"></a>    $page_obj = new $page_class();
<a name="line218"></a>    $model_obj = new $model_class();
<a name="line219"></a>    
<a name="line220"></a>    //set properties
<a name="line221"></a>    $model_obj->class_path = $mdl_path;
<a name="line222"></a>    $page_obj->class_path = $cls_path;
<a name="line223"></a>    $page_obj->css_path = $css_path;
<a name="line224"></a>    $page_obj->js_path = $js_path;
<a name="line225"></a>    $page_obj->php_path = $php_path;
<a name="line226"></a>    $page_obj->model = $model_obj;
<a name="line227"></a>
<a name="line228"></a>    self::$page_obj = $page_obj;    
<a name="line229"></a>  }
<a name="line230"></a>
<a name="line231"></a>  /**
<a name="line232"></a>   * Get instance of a block
<a name="line233"></a>   * @param string $block The name of block (eg. 'menu','header',...)
<a name="line234"></a>   */
<a name="line235"></a>  public static function get_block($block,$module=null) {
<a name="line236"></a>    if ($module===null)
<a name="line237"></a>      $module = request::get_module_name();
<a name="line238"></a>    $skin = self::$skin;  
<a name="line239"></a>
<a name="line240"></a>    //file paths    
<a name="line241"></a>    $mdl_path = "mcv/blocks/models/$module"."_".$block."_block_model.php";
<a name="line242"></a>    $cls_path = "mcv/blocks/controllers/$module"."_".$block."_block.php";
<a name="line243"></a>    $css_path = "mcv/blocks/views/css/$module"."_".$block."_"."$skin.css";
<a name="line244"></a>    $js_path = "mcv/blocks/views/js/$module"."_".$block."_block.js";
<a name="line245"></a>    $php_path = "mcv/blocks/views/php/$module"."_".$block."_block.php";
<a name="line246"></a>    
<a name="line247"></a>    //block has css to follow skin, but if so such css file, use default
<a name="line248"></a>    //skin file of block (ie. $module_$block_block.css)
<a name="line249"></a>    if (!file_exists($css_path))
<a name="line250"></a>      $css_path = "mcv/blocks/views/css/$module"."_".$block."_block.css";
<a name="line251"></a>    
<a name="line252"></a>    //load classes
<a name="line253"></a>    if (!file_exists($mdl_path)) {
<a name="line254"></a>      response::error("'$mdl_path' not found");
<a name="line255"></a>      exit;
<a name="line256"></a>    }
<a name="line257"></a>    if (!file_exists($cls_path)) {
<a name="line258"></a>      response::error("'$cls_path' not found");
<a name="line259"></a>      exit;
<a name="line260"></a>    }    
<a name="line261"></a>    require_once($mdl_path); //model
<a name="line262"></a>    require_once($cls_path); //controller
<a name="line263"></a>
<a name="line264"></a>    //create instance of layout
<a name="line265"></a>    $block_class = $module."_".$block."_block";
<a name="line266"></a>    $model_class = $block_class."_model";
<a name="line267"></a>    $block_obj = new $block_class();
<a name="line268"></a>    $model_obj = new $model_class();
<a name="line269"></a>    
<a name="line270"></a>    //set properties
<a name="line271"></a>    $model_obj->class_path = $mdl_path;
<a name="line272"></a>    $block_obj->class_path = $cls_path;
<a name="line273"></a>    $block_obj->css_path = $css_path;
<a name="line274"></a>    $block_obj->js_path = $js_path;
<a name="line275"></a>    $block_obj->php_path = $php_path;
<a name="line276"></a>    $block_obj->model = $model_obj;
<a name="line277"></a>    
<a name="line278"></a>    //set block ID
<a name="line279"></a>    if (!isset(self::$blocks[$block]))    
<a name="line280"></a>      self::$blocks[$block] = array();
<a name="line281"></a>    $count = count(self::$blocks[$block]);
<a name="line282"></a>    $block_obj->id = $block.$count;
<a name="line283"></a>    self::$blocks[$block][$count] = &$block_obj;
<a name="line284"></a>
<a name="line285"></a>    return $block_obj;
<a name="line286"></a>  }
<a name="line287"></a>  
<a name="line288"></a>  /** 
<a name="line289"></a>   * Initialise all classes (mostly static ones)
<a name="line290"></a>   */
<a name="line291"></a>  public static function initialise_all() {
<a name="line292"></a>    if (file_exists("dump.txt"))
<a name="line293"></a>      unlink("dump.txt");
<a name="line294"></a>    
<a name="line295"></a>    config::initialise();
<a name="line296"></a>    request::initialise();
<a name="line297"></a>    session::initialise();
<a name="line298"></a>    phrase::initialise();
<a name="line299"></a>    
<a name="line300"></a>    self::load_module_info();
<a name="line301"></a>    self::load_page_info();  
<a name="line302"></a>
<a name="line303"></a>    self::$website = config::get_website_name();
<a name="line304"></a>    self::$title = utils::get_arr_value(self::$page,"title");    
<a name="line305"></a>  }
<a name="line306"></a>  
<a name="line307"></a>  /**
<a name="line308"></a>   * Module authentication page should call this function when the 
<a name="line309"></a>   * requirements for accessing the module are all fulfilled.
<a name="line310"></a>   */
<a name="line311"></a>  public static function module_auth_passed() {
<a name="line312"></a>    $module_name = request::get_module_name();
<a name="line313"></a>    session::set_value($module_name."_auth","passed");
<a name="line314"></a>  }
<a name="line315"></a>  
<a name="line316"></a>  /**
<a name="line317"></a>   * Perform a sign-out action
<a name="line318"></a>   */
<a name="line319"></a>  public static function sign_out() {
<a name="line320"></a>    session::destroy();
<a name="line321"></a>  }
<a name="line322"></a>  
<a name="line323"></a>  /**
<a name="line324"></a>   * Check if current module is protected
<a name="line325"></a>   * @return boolean 'true' if protected, 'false' otherwise
<a name="line326"></a>   */
<a name="line327"></a>  private static function current_module_protected() {
<a name="line328"></a>    //no 'protected' tag in module.xml
<a name="line329"></a>    if (!isset(self::$module["protected"]))
<a name="line330"></a>      return true;
<a name="line331"></a>      
<a name="line332"></a>    //no value for 'protected' tag  
<a name="line333"></a>    if (!is_string(self::$module["protected"]))
<a name="line334"></a>      return true;
<a name="line335"></a>      
<a name="line336"></a>    //value of 'protected' tag isn't string "false"  
<a name="line337"></a>    if (strtolower(trim(self::$module["protected"]!=="false")))
<a name="line338"></a>      return true;
<a name="line339"></a>      
<a name="line340"></a>    return false;
<a name="line341"></a>  }
<a name="line342"></a>  
<a name="line343"></a>  /**
<a name="line344"></a>   * Get list of existing modules (xml files in 'modules' directory)
<a name="line345"></a>   * @return array The list of modules
<a name="line346"></a>   */
<a name="line347"></a>  public static function get_module_list() {
<a name="line348"></a>    $files = utils::get_files_in("modules","xml");
<a name="line349"></a>    if (count($files)==0)
<a name="line350"></a>      return array();
<a name="line351"></a>      
<a name="line352"></a>    //file names to module names  
<a name="line353"></a>    $modules = array();  
<a name="line354"></a>    foreach ($files as $file) {
<a name="line355"></a>      $parts = pathinfo($file);
<a name="line356"></a>      array_push($modules,$parts["filename"]);
<a name="line357"></a>    }
<a name="line358"></a>    
<a name="line359"></a>    return $modules;
<a name="line360"></a>  }
<a name="line361"></a>
<a name="line362"></a>  /**
<a name="line363"></a>   * Get list of protected modules
<a name="line364"></a>   * @return array The list of protected modules
<a name="line365"></a>   */
<a name="line366"></a>  public static function get_protected_modules() {
<a name="line367"></a>    $module_names = self::get_module_list();
<a name="line368"></a>    $protecteds = array();
<a name="line369"></a>    
<a name="line370"></a>    //get module xml
<a name="line371"></a>    foreach ($module_names as $module_name) {
<a name="line372"></a>      $module_name = strtolower(trim($module_name));
<a name="line373"></a>      if ($module_name=="devtools")
<a name="line374"></a>        continue;
<a name="line375"></a>      
<a name="line376"></a>      $info = xml::arr_from_file("modules/$module_name.xml");
<a name="line377"></a>      if (!isset($info["protected"]))
<a name="line378"></a>        array_push($protecteds,$module_name);
<a name="line379"></a>      else 
<a name="line380"></a>      if (!is_string($info["protected"])) 
<a name="line381"></a>        array_push($protecteds,$module_name);
<a name="line382"></a>      else {
<a name="line383"></a>        $protected = strtolower(trim($info["protected"]));
<a name="line384"></a>        if ($protected!=="false")
<a name="line385"></a>          array_push($protecteds,$module_name);
<a name="line386"></a>      }
<a name="line387"></a>    }//foreach
<a name="line388"></a>    
<a name="line389"></a>    return $protecteds;
<a name="line390"></a>  }
<a name="line391"></a>  
<a name="line392"></a>  /**
<a name="line393"></a>   * Break all output buffers (those started by ob_start)
<a name="line394"></a>   */
<a name="line395"></a>  public static function break_all_buffers() {
<a name="line396"></a>    while (ob_get_level()>0)
<a name="line397"></a>      ob_end_clean();
<a name="line398"></a>  }
<a name="line399"></a>  
<a name="line400"></a>  /**
<a name="line401"></a>   * Check if the access to certain module is already granted
<a name="line402"></a>   * @return boolean 'true' is already granted, 'false' otherwise
<a name="line403"></a>   */
<a name="line404"></a>  private static function module_access_granted() {
<a name="line405"></a>    $module_name = request::get_module_name();
<a name="line406"></a>    $auth_status = session::get_value($module_name."_auth");
<a name="line407"></a>    if (!is_string($auth_status))    
<a name="line408"></a>      return false;
<a name="line409"></a>
<a name="line410"></a>    //return
<a name="line411"></a>    return $auth_status==="passed";    
<a name="line412"></a>  }
<a name="line413"></a>  
<a name="line414"></a>  /**
<a name="line415"></a>   * Check module protection (module authentication)
<a name="line416"></a>   */
<a name="line417"></a>  private static function check_module_protection() { 
<a name="line418"></a>    $module_name = strtolower(trim(request::get_module_name())); 
<a name="line419"></a>    $page_name = strtolower(trim(request::get_page_name()));
<a name="line420"></a>    
<a name="line421"></a>    //no protection for 'devtools' coz accessible only from localhost
<a name="line422"></a>    if ($module_name=="devtools")
<a name="line423"></a>      return; 
<a name="line424"></a>     
<a name="line425"></a>    //redirect to authentication page if module is protected     
<a name="line426"></a>    if (self::current_module_protected()) 
<a name="line427"></a>    if (!self::module_access_granted())
<a name="line428"></a>    if ($page_name!=="modauth")
<a name="line429"></a>      response::redirect_to("$module_name"."_modauth");
<a name="line430"></a>  }
<a name="line431"></a>  
<a name="line432"></a>  /**
<a name="line433"></a>   * Check module accessibility
<a name="line434"></a>   */
<a name="line435"></a>  public static function check_security() { 
<a name="line436"></a>    $module_name = strtolower(trim(request::get_module_name()));
<a name="line437"></a>    
<a name="line438"></a>    //get module status
<a name="line439"></a>    $module_is_online = strtolower(trim(self::$module["online"])); 
<a name="line440"></a>    if ($module_is_online!=="true") {
<a name="line441"></a>      response::error("Module '$module_name' is offline");
<a name="line442"></a>      exit; 
<a name="line443"></a>    }
<a name="line444"></a>    
<a name="line445"></a>    //module 'devtools' accessible only from localhost
<a name="line446"></a>    if ($module_name=="devtools" && !self::is_localhost()) {
<a name="line447"></a>      response::error("Network access to 'devtools' denied");
<a name="line448"></a>      exit;
<a name="line449"></a>    }
<a name="line450"></a>      
<a name="line451"></a>    //check accessibility from internet
<a name="line452"></a>    $internet = self::$module["accessible"]["from"]["internet"];
<a name="line453"></a>    $internet = strtolower(trim($internet));
<a name="line454"></a>    if ($internet!=="true") 
<a name="line455"></a>      if (!self::is_localhost()) {
<a name="line456"></a>        response::error("Network access to '$module_name' denied");
<a name="line457"></a>        exit;
<a name="line458"></a>      }
<a name="line459"></a>      
<a name="line460"></a>    self::check_module_protection();
<a name="line461"></a>  }
<a name="line462"></a>  
<a name="line463"></a>  /**
<a name="line464"></a>   * Check user's preferences (skin & language)
<a name="line465"></a>   */
<a name="line466"></a>  public static function check_preferences() {
<a name="line467"></a>    $setlang = request::get_url_var("setlang");
<a name="line468"></a>    $setskin = request::get_url_var("setskin");
<a name="line469"></a>    
<a name="line470"></a>    //new lang preference?
<a name="line471"></a>    if ($setlang!=null)
<a name="line472"></a>      cookie::set("lang",$setlang);
<a name="line473"></a>  
<a name="line474"></a>    //new skin preference?
<a name="line475"></a>    if ($setskin!=null)
<a name="line476"></a>      cookie::set("skin",$setskin);
<a name="line477"></a>  
<a name="line478"></a>    //check skin in cookie jar
<a name="line479"></a>    $skin = cookie::get("skin");
<a name="line480"></a>    if ($skin==null || strlen($skin)==0)
<a name="line481"></a>      self::$skin = config::get_default_skin();
<a name="line482"></a>    else 
<a name="line483"></a>      self::$skin = $skin;
<a name="line484"></a>      
<a name="line485"></a>    //check language in cookie jar  
<a name="line486"></a>    $lang = cookie::get("lang");
<a name="line487"></a>    if ($lang==null || strlen($lang)==0)    
<a name="line488"></a>      self::$lang = config::get_default_lang();
<a name="line489"></a>    else
<a name="line490"></a>      self::$lang = $lang;
<a name="line491"></a>  }
<a name="line492"></a>  
<a name="line493"></a>  /**
<a name="line494"></a>   * Get created layout object
<a name="line495"></a>   */
<a name="line496"></a>  public static function layout() {
<a name="line497"></a>    return self::$layout_obj;
<a name="line498"></a>  }
<a name="line499"></a>  
<a name="line500"></a>  /**
<a name="line501"></a>   * Get created page object  
<a name="line502"></a>   */
<a name="line503"></a>  public static function page() {
<a name="line504"></a>    return self::$page_obj;
<a name="line505"></a>  }
<a name="line506"></a>  
<a name="line507"></a>  /**
<a name="line508"></a>   * Check if script called from localhost, meaning whether the web browser
<a name="line509"></a>   * running on server or on a network computer   
<a name="line510"></a>   * @return boolean 'true' if called from localhost
<a name="line511"></a>   */
<a name="line512"></a>  public static function is_localhost() {
<a name="line513"></a>    $remote = strtolower($_SERVER["REMOTE_ADDR"]); 
<a name="line514"></a>    
<a name="line515"></a>    //IP v4 or IP v6 loopbacks
<a name="line516"></a>    return $remote=="127.0.0.1" || $remote=="::1";
<a name="line517"></a>  }
<a name="line518"></a>  
<a name="line519"></a>  /**
<a name="line520"></a>   * Render 'head' tag and information inside
<a name="line521"></a>   */
<a name="line522"></a>  private static function render_head_tag() {
<a name="line523"></a>    $skin = self::$skin;
<a name="line524"></a>    $file_path = "skins/$skin/global.php";
<a name="line525"></a>    require_once($file_path);
<a name="line526"></a>  }
<a name="line527"></a>  
<a name="line528"></a>  /**
<a name="line529"></a>   * Render the whole layout (which contains page)
<a name="line530"></a>   */
<a name="line531"></a>  private static function render_layout() {
<a name="line532"></a>    //render
<a name="line533"></a>    self::$layout_obj->render_html();
<a name="line534"></a>  }
<a name="line535"></a>
<a name="line536"></a>  /**
<a name="line537"></a>   * Render the requested page
<a name="line538"></a>   */
<a name="line539"></a>  public static function render_page() {
<a name="line540"></a>    //render
<a name="line541"></a>    self::$page_obj->render_html();
<a name="line542"></a>  }
<a name="line543"></a>  
<a name="line544"></a>  /**
<a name="line545"></a>   * Render the whole web page
<a name="line546"></a>   */
<a name="line547"></a>  public static function render_webpage() {
<a name="line548"></a>    self::create_layout_obj();
<a name="line549"></a>    self::create_page_obj();  
<a name="line550"></a>  
<a name="line551"></a>    ob_start(); 
<a name="line552"></a>    self::render_head_tag();
<a name="line553"></a>    self::render_layout();
<a name="line554"></a>    echo ob_get_clean();
<a name="line555"></a>  }
<a name="line556"></a>}</pre>
<div class="header">
<h1>Cornice</h1>
<ul>
<li><a href="../overview-summary.html">Overview</a></li>
<li>Package</li><li>Class</li><li>Tree</li><li><a href="../overview-files.html">Files</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../todo-list.html">Todo</a></li>
<li><a href="../index-all.html">Index</a></li>
</ul>
</div>

<div class="small_links">
<a href="../index.html" target="_top">Frames</a>
<a href="../source\system.php.html" target="_top">No frames</a>
</div>
<hr>

<p id="footer">This document was generated by <a href="http://peej.github.com/phpdoctor/">PHPDoctor: The PHP Documentation Creator</a></p>

</body>

</html>